
namespace Fine.Collections.Const
{
    /// <summary>
    /// Immutable set. 
    /// All items are different, nulls are not allowed.
    /// </summary>
    /// <typeparam name="T">type of an item.</typeparam>
    public abstract class ConstSet<T> : ConstArray<T>
    {


        #region CONSTRUCTORS

        internal ConstSet(int firstIndex, T[] array, int count, bool takeOwnership) 
            : base(firstIndex, array, count, takeOwnership) 
        {}

        #endregion




        #region SOME ABSTRACT FUNCTIONS IMPLEMENTATION


        public override bool Contains(T item)
        {
            return this.IndexOf(item) != int.MinValue;
        }


        /// <summary>
        /// Checks whether the specified item contains in the set.
        /// </summary>
        /// <param name="item">items to check for.</param>
        /// <returns>1 if contains, 0 if no.</returns>
        public override int CountOf(T item)
        {
            return this.Contains(item) ? 1 : 0;
        }


        /// <summary>
        /// Returns this set as a list, preserving order.
        /// </summary>
        /// <returns></returns>
        public override ConstList<T> ToList()
        {
            return new ConstList<T>(firstIndex, arr, count, true);
        }


        /// <summary>
        /// Returns itself. Does nothing.
        /// </summary>
        /// <returns>itself.</returns>
        public override ConstSet<T> ToSet()
        {
            return this;
        }

        #endregion




    }
}